package solutions;


class Euler005 {
  
  public static void main(String[] args){
    
    /*	 2	 3 	 4    5..13...17 18	 19
     * 2
     * 3
     * 5
     * 7
     * 11
     * 13
     * 17
     * 19
     */
    
    int[][] matrix = new int[8][18];
    int[] factors = new int[]{2, 3, 5, 7, 11, 13, 17, 19};
    
    //fill the matrix with zeros!!
    
    for(int i = 0; i< 8; i++){
    	for(int j = 0; j < 18; j++)
    		matrix[i][j] = 0;
    }
    
    
    
    
    
    for(int i = 0; i < 18; i++){ //matrix(0) represents 2; matrix(17) represents 19
    
     int pos = 0, rest = i+2;
     while(pos < factors.length && rest > 1){
        
    	 if(rest % factors[pos] == 0){
    		 rest = rest / factors[pos];
    		 matrix[pos][i] += 1;
    	 }
    	 else{
    		 pos++;
    	 }
	  }
    }

    int result  = 1;
    for(int i = 0; i < factors.length; i++){
    	result *= (int) Math.pow((double) factors[i], (double) max(matrix[i]));
    }
    
    System.out.println("Result: " + result);
    
	

    
    
  }
  
  
  private static int max(int[] array){
	  
	  if(array.length == 1)
		  return array[0];
	  
	  int max = array[0];
	  for(int i = 1; i < array.length; i++){
		  if(array[i] > max)
			  max = array[i];
	  }
	  
	  return max;
  }
  
  
  
  

}
